﻿using UnityEngine;
using System.Collections;

public class GuiModelAnim : MonoBehaviour {

	private Animator anim;
	private float timer;
	private int dir = 0;
	// Use this for initialization
	void Start () {
		anim = GetComponent<Animator> ();
		anim.speed = 0.4f;
		timer = 5f;
	}
	
	// Update is called once per frame
	void Update () {
		timer -= Time.deltaTime;
		if(timer<0) {
			timer = 5f;
			//wybór wyświetlanego sprite'a (stanu w animatorze)
			switch(dir) {
				case 0: dir=1; break;
				case 1: dir=3; break;
				case 3: dir=0; break;
			}

			anim.SetInteger ("direction", dir);
			//to samo dla dzieci danego obiektu
			foreach (Transform child in transform)
			{
				Animator childAnim = child.GetComponent<Animator>();
				childAnim.SetInteger ("direction", dir);
			}
		}
	}
}
